import React from 'react'
import { Divider, Modal, Form, Input, Icon, Popover, Button, Tag } from 'antd'
import LwjTable from 'components/LwjTable/LwjTable'
import { LwjSowPicList, Loader } from 'components'
import { auditStatus } from "utils/enumConfig"
import styles from "./List.less"
import moment from 'moment'

let colors = {
  'UNSUBMIT': '',
  'PENDING': 'blue',
  'AUDIT_SUCCESS': 'green',
  'AUDIT_FAIL': 'red'
};

const List = ({
  load,
  dispatch,
  global,
  typeObj,
  ...tableProps
}) => {

  const onShowDetail = (record) => {
    dispatch({
      type: 'salesDistributorRegistryApply/setDetailVisible',
      payload: true
    })
    dispatch({
      type: 'salesDistributorRegistryApply/detail',
      payload: record.id
    })
  }
  const setCurrentItem = (record) => {
    dispatch({
      type: 'salesDistributorRegistryApply/setCurrentItem',
      payload: record
    })
  }
  const setFast = (record) => {
    dispatch({
      type: 'salesDistributorRegistryApply/setCurrentItem',
      payload: record
    })
    dispatch({
      type: 'salesDistributorRegistryApply/setFastVisible',
      payload: true
    })
  }

  const columns = [
    {
      title: '店铺名称',
      dataIndex: 'displayName',
      key: 'displayName',
      width: "25%",
    },
    {
      title: '用户类型',
      dataIndex: 'enterRole',
      key: 'enterRole',
      width: "10%",
      render: (text) => (typeObj[text])
    },
    {
      title: '手机号码',
      dataIndex: 'mobile',
      key: 'mobile',
      width: "10%"
    },
    {
      title: '入驻状态',
      dataIndex: 'auditStatus',
      key: 'auditStatus',
      width: "10%",
      render: (text, record, index) => (auditStatus[record.auditStatus])
    },
    {
      title: '注册时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: "10%",
      render: (text, record, index) => (moment(record.createTime).format('YYYY-MM-DD HH:mm:ss'))
    },
    {
      title: '审核事项',
      dataIndex: 'toAuditItems',
      key: 'toAuditItems',
      width: "15%",
      render: (text, record, index) => (
        <div>
          {
            record.auditStatus != 'AUDIT_FAIL' && record.realNameAuditStatus
              ? (<div>实名认证： <Tag color={colors[record.realNameAuditStatus]} style={{ fontWeight: 'normal' }}>{auditStatus[record.realNameAuditStatus]}</Tag></div>)
              : null
          }
          {
            record.auditStatus != 'AUDIT_FAIL' && record.businessAuditStatus
              ? (<div>营业执照： <Tag color={colors[record.businessAuditStatus]} style={{ fontWeight: 'normal' }}>{auditStatus[record.businessAuditStatus]}</Tag></div>)
              : null
          }
        </div>
      )
    },
    {
      title: '操作',
      key: 'handle',
      render: (text, record) => (
        <span>
          {<a onClick={() => onShowDetail(record)}>查看</a>}
          {<Divider type="vertical" />}
          {record.auditStatus == "AUDIT_SUCCESS" && <a onClick={() => setFast(record)}>快速分配商品库</a>}
        </span>
      )
    }
  ];

  return (
    <LwjTable
      {...tableProps}
      dispatch={dispatch}
      columns={columns} />
  )
};
export default Form.create()(List)
